class StorageManager {
    constructor() {
        this.CATEGORIES_KEY = 'noteCategories';
        this.NOTES_KEY = 'notes';
    }

    // 获取分类，现在返回树形结构
    getCategories() {
        const defaultCategories = [
            { 
                id: 'all',
                name: '全部笔记',
                isDefault: true
            },
            {
                id: 'uncategorized',
                name: '未分类',
                isDefault: true
            }
        ];

        const categories = JSON.parse(localStorage.getItem(this.CATEGORIES_KEY));
        return categories || defaultCategories;
    }

    // 保存分类
    saveCategories(categories) {
        localStorage.setItem(this.CATEGORIES_KEY, JSON.stringify(categories));
    }

    // 获取分类的完整路径
    getCategoryPath(categoryId) {
        const categories = this.getCategories();
        const path = [];
        
        const findPath = (cats, targetId) => {
            for (const cat of cats) {
                if (cat.id === targetId) {
                    path.push(cat.name);
                    return true;
                }
                if (cat.children) {
                    if (findPath(cat.children, targetId)) {
                        path.unshift(cat.name);
                        return true;
                    }
                }
            }
            return false;
        };

        findPath(categories, categoryId);
        return path;
    }

    // 获取笔记
    getNotes() {
        return JSON.parse(localStorage.getItem(this.NOTES_KEY) || '[]');
    }

    // 保存笔记
    saveNotes(notes) {
        localStorage.setItem(this.NOTES_KEY, JSON.stringify(notes));
    }
}


